/**
 * @file featureListColumns.js
 * @author
 */

import React from 'react';
import { Link } from 'dva/router';
import utils from './utils';
import fx from './utils/fx';

const colorScore = (text) => {
	const n = Number.parseFloat(text).toFixed(2);
	const color = n < 60 ? 'green' : 'red';
	return (<span style={{ color }}>{n}</span>);
};

const columns = [
	{
		title: '交易员姓名 / ID',
		dataIndex: 'trader',
		render: (text, record, index) => {
			return record.trader + ' / ' + record.trader;
		},
		width: 120,
	}
];

export default function getColumns(featuresMapping) {
	const cols = [...columns];
	featuresMapping.map((item) => {
		const fieldName = utils.toCamelCase(item.columnName);
		if (item.weight >= 1) {
			if (fieldName == 'allTimePnl') {
				cols.push({
					title: item.showName,
					dataIndex: fieldName,
					render: (text) => { return fx.colorMoney(text); },
					sorter: true,
					orderIndex: item.orderIndex,
					width: 120,
				});
			} else if (fieldName == 'avgDailyVolume') {
				cols.push({
					title: item.showName,
					dataIndex: fieldName,
					render: (text) => { return fx.formatMoney(text); },
					sorter: true,
					orderIndex: item.orderIndex,
					width: 120,
				});
			} else if (fieldName == 'avgDuration') {
				cols.push({
					title: item.showName,
					dataIndex: fieldName,
					render: (s) => { return fx.formatSeconds(s); },
					sorter: true,
					orderIndex: item.orderIndex,
					width: 120,
				});
			} else if (fieldName == 'fdtScore'
			|| fieldName == 'profitability'
			|| fieldName == 'riskCtrl') {
				cols.push({
					title: item.showName,
					dataIndex: fieldName,
					render: (text) => { return colorScore(text); },
					sorter: true,
					orderIndex: item.orderIndex,
					width: 120,
				});
			} else {
				cols.push({
					title: item.showName,
					dataIndex: fieldName,
					render: text => (text ? text.toFixed(2) : 0),
					sorter: true,
					orderIndex: item.orderIndex,
					width: 120,
				});
			}
		}
	});

	cols.sort((a, b) => {
		return (a.orderIndex - a.orderIndex);
	});

	return cols;
}
